package com.thread.threadpool;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author: may
 * @date: 2021年04月15日 20:06
 */
public class TestFuture {
    public static void main(String[] args) {
        ExecutorService es = null;
        try {
            es = Executors.newCachedThreadPool();
            Future<String> future = es.submit(() -> {
                System.out.println("i am callable");
                return "future";
            });
            System.out.println(future.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        } finally {
            es.shutdown();
        }
    }
}
